﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WmsApp.Report;

namespace WmsApp.Window
{
    public partial class FormPublish : BaseForm
    {
        public FormPublish()
        {
            InitializeComponent();
        }

        public override string HeadText
        {
            get
            {
                return "更新发布";
            }
        }

        private void CmdSelect_Click(object sender, EventArgs e)
        {
            if (this.openFileDialogMain.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.textEditFileName.Text = this.openFileDialogMain.FileName;
            }
        }

        private void CmdPublish_Click(object sender, EventArgs e)
        {
            if (File.Exists(this.textEditFileName.Text))
            {
                if (System.Windows.Forms.DialogResult.OK == XtraMessageBox.Show("确实要发布吗？", "提问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {
                    try
                    {
                        string tFileName =
                            this.textEditFileName.Text.Substring(this.textEditFileName.Text.LastIndexOf('\\') + 1).ToLower();
                        int version = Factory.WmsServiceFactory.GetServiceClient().PublishFile(tFileName, File.ReadAllBytes(this.textEditFileName.Text));
                        XtraMessageBox.Show("发布成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        Exceptions.ExceptionHandler.ShowException(ex);
                    }

                }
            }
        }

        private void CmdSaveSchema_Click(object sender, EventArgs e)
        {
            try
            {
                ReportFactory.WriteXmlSchema("入库单");
                ReportFactory.WriteXmlSchema("出库单");
                ReportFactory.WriteXmlSchema("借用单");
                ReportFactory.WriteXmlSchema("送修单");
                ReportFactory.WriteXmlSchema("付款申请单");
            }
            catch (Exception ex)
            {
                Exceptions.ExceptionHandler.ShowException(ex);
            }
        }
    }
}